# - Find OIS includes and library
#
# This module defines
#  OIS_INCLUDE_DIRS
#  OIS_LIBRARIES, the libraries to link against to use OIS.
#  OIS_LIBRARY_DIRS, the location of the libraries
#  OIS_FOUND, If false, do not try to use OIS
#
# Copyright © 2007-2008, Matt Williams
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# On a new cmake run, we do not need to be verbose
IF(OIS_INCLUDE_DIR AND OIS_LIBRARY)
	SET(OIS_FIND_QUIETLY TRUE)
ENDIF(OIS_INCLUDE_DIR AND OIS_LIBRARY)

IF (WIN32)
	MESSAGE(STATUS "Looking for OIS")
	SET(OGRESDK $ENV{OGRE_HOME})
	SET(OGRESOURCE $ENV{OGRE_NEW})
	IF (OGRESDK)
		MESSAGE(STATUS "Using OIS in OGRE SDK")
		SET(OGRESDK $ENV{OGRE_HOME})
		STRING(REGEX REPLACE "[\\]" "/" OGRESDK "${OGRESDK}")
		SET(OIS_INCLUDE_DIRS ${OGRESDK}/include)
		SET(OIS_LIBRARY_DIRS ${OGRESDK}/lib)
		SET(OIS_LIBRARIES debug OIS_d optimized OIS)
	ELSEIF (OGRESOURCE)
		MESSAGE(STATUS "Using OIS in OGRE dependencies")
		SET(OIS_INCLUDE_DIRS C:/ogrenew/Dependencies/include)
		SET(OIS_LIBRARY_DIRS C:/ogrenew/Dependencies/lib/Release C:/ogrenew/Dependencies/lib/Debug)
		SET(OIS_LIBRARIES debug OIS_d optimized OIS)
	ELSE (OGRESDK)
		IF (NOT DEPENDENCIES_PATH)
			MESSAGE(STATUS "Please set DEPENDENCIES_PATH (the directory containing 'common' and 'dependencies')")
		ELSE (NOT DEPENDENCIES_PATH)
			SET(CEGUIOGRE_INCLUDE_DIRS ${DEPENDENCIES_PATH}/dependencies/Ogre/OIS)
			SET(CEGUIOGRE_LIBRARIES optimized OIS debug OIS_d)
			SET(CEGUIOGRE_LIBRARY_DIRS optimized ${DEPENDENCIES_PATH}/dependencies/lib/release debug ${DEPENDENCIES_PATH}/dependencies/lib/debug)
		ENDIF (NOT DEPENDENCIES_PATH)
	ENDIF (OGRESDK)
ELSE(WIN32)
	IF(PKG_CONFIG_FOUND)
		PKG_SEARCH_MODULE(OIS OIS)
		SET(OIS_INCLUDE_DIR ${OIS_INCLUDE_DIRS})
		SET(OIS_LIBRARY ${OIS_LIBRARIES})
	ENDIF(PKG_CONFIG_FOUND)
	IF(NOT OIS_FOUND)

	ENDIF(NOT OIS_FOUND)
ENDIF(WIN32)

SET(OIS_INCLUDE_DIR ${OIS_INCLUDE_DIR} CACHE STRING "Directory containing OIS header files")
SET(OIS_LIBRARY ${OIS_LIBRARY} CACHE STRING "Library name of OIS library")

#Do some preparation
SEPARATE_ARGUMENTS(OIS_INCLUDE_DIRS)
SEPARATE_ARGUMENTS(OIS_LIBRARIES)

SET(OIS_INCLUDE_DIRS ${OIS_INCLUDE_DIRS})
SET(OIS_LIBRARIES ${OIS_LIBRARIES})
SET(OIS_LIBRARY_DIRS ${OIS_LIBRARY_DIRS})

MARK_AS_ADVANCED(OIS_INCLUDE_DIRS OIS_LIBRARIES OIS_LIBRARY_DIRS)

IF (OIS_INCLUDE_DIR AND OIS_LIBRARY)
	SET(OIS_FOUND TRUE)
ENDIF (OIS_INCLUDE_DIR AND OIS_LIBRARY)

IF (OIS_FOUND)
	IF (NOT OIS_FIND_QUIETLY)
		MESSAGE(STATUS "  libraries : ${OIS_LIBRARY} from ${OIS_LIBRARY_DIRS}")
		MESSAGE(STATUS "  includes  : ${OIS_INCLUDE_DIR}")
	ENDIF (NOT OIS_FIND_QUIETLY)
ELSE (OIS_FOUND)
	IF (OIS_FIND_REQUIRED)
		MESSAGE(FATAL_ERROR "Could not find OIS")
	ENDIF (OIS_FIND_REQUIRED)
ENDIF (OIS_FOUND)
